home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 September (IDG) / Sep99.iso / Shareware World / Info / For Developers / Finder Flags Plugin / Finder Flags Sources / Finder Flags Postlinker / SetFile.c < prev   
Encoding:
C/C++ Source or Header  |  1999-06-19  |  5.3 KB  |  240 lines  |  [TEXT/CWIE]

  1. /*
  2.  *  SetFile Linker.c    - public interface to SetFile Linker
  3.  *
  4.  *  Copyright © 1993 metrowerks inc.  All rights reserved.
  5.  *
  6.  */
  7.  
  8. #define    beginC    extern "C" {
  9. #define    concludeC    }
  10. /*
  11. SetFile [option…] file/folder…
  12.     -a attributes           # attributes (lowercase = 0, uppercase = 1)*
  13.     -c creator              # file creator
  14.     -d date                 # creation date (mm/dd/yy [hh:mm[:ss] [AM | PM]])*
  15.     -l h,v                  # ICON location (horizontal,vertical)*
  16.     -m date                 # modification date (mm/dd/yy [hh:mm[:ss] [AM | PM]])*
  17.     -noResolve              # don't resolve aliases on the input file path
  18.     -t type                 # file type
  19.  
  20.     Note: Period (.) represents the current date and time.
  21.     Note: The following attributes may be used with the -a option:
  22.         A   Alias file
  23.         V   Invisible*
  24.         B   Bundle
  25.         S   System (name locked)
  26.         T   Stationary
  27.         C   Custom icon*
  28.         L   Locked
  29.         I   Inited*
  30.         N   No INIT resources
  31.         M   Shared (can run multiple times)
  32.         W   Always switch launch (if possible)
  33.         D   Desktop*
  34.     *Note: Options/attributes marked with an asterisk (*) are allowed with folders
  35. */
  36. /* standard headers */
  37. #include <stdio.h>
  38. #include <string.h>
  39.  
  40. /* system headers */
  41. #include <Strings.h>
  42.  
  43. /* compiler headers */
  44. #include <A4Stuff.h>
  45. #include <DropInCompilerLinker.h>
  46. #include <CWPluginErrors.h>
  47. #include <Files.h>
  48. #include <Finder.h>
  49. #include <Errors.h>
  50. /* project headers */
  51. #include "SetFilePanel.h"
  52. #include "EvenMoreFiles.h"
  53.  
  54.  
  55. /* use standard CodeWarrior debugger */
  56. #define kDebuggerCreator    'MWDB'
  57.  
  58. #define    kNoChange            '????'
  59. beginC
  60.  
  61. /* prototypes of local functions */
  62. CWResult    Link (CWPluginContext inContext);
  63. CWResult    Disassemble (CWPluginContext inContext);
  64. CWResult    GetTargetInfo (CWPluginContext inContext);
  65. CWResult     MyGetPreferences (CWPluginContext context, SetFilePref* prefData);
  66.  
  67.  
  68. /*
  69.  *    main    -    main entry-point for Drop-In SetFile linker
  70.  *
  71.  */
  72.  
  73. pascal short    main (
  74.     CWPluginContext    inContext)
  75. {
  76.     CWResult    result;
  77.     long        request;
  78.     
  79.     /* set up global world (68K only) */
  80.     EnterCodeResource();
  81.     // DebugStr("\p SetFile main");        
  82.     
  83.     if (CWGetPluginRequest (inContext, &request) != noErr) {
  84.         ExitCodeResource ();
  85.         return cwErrRequestFailed;
  86.     }
  87.     
  88.     result = noErr;
  89.         
  90.     /* dispatch on linker request */
  91.     switch (request)
  92.     {
  93.     case reqInitLinker:
  94.         /* linker has just been loaded into memory */
  95.         break;
  96.         
  97.     case reqTermLinker:
  98.         /* linker is about to be unloaded from memory */
  99.         break;
  100.         
  101.     case reqLink:
  102.         /* build the final executable */
  103.         result = Link(inContext);
  104.         break;
  105.  
  106.     case reqTargetInfo:
  107.         /* return info describing target characteristics */
  108.         result = GetTargetInfo(inContext);
  109.         break;
  110.         
  111.     default:
  112.         result = cwErrRequestFailed;
  113.         break;
  114.     }
  115.     
  116.     result = CWDonePluginRequest (inContext, result);
  117.     
  118.     /* tear down global world (68K only) */
  119.     ExitCodeResource();
  120.     
  121.     /* return result code */
  122.     return result;
  123. }
  124.  
  125.  
  126. CWResult    GetTargetInfo (
  127.     CWPluginContext    inContext)
  128. {
  129.     CWTargetInfo    targetInfo;
  130.     SetFilePref        prefsData;
  131.     CWResult        err;
  132.     
  133.     err = CWGetTargetInfo (inContext, &targetInfo);
  134.     
  135.     if (err != noErr)
  136.         return err;
  137.     
  138.     /* load the relevant prefs */
  139.     err = MyGetPreferences(inContext, &prefsData);
  140.     
  141.     if (err == noErr) {
  142.         /* we can only run applications */
  143.         targetInfo.canRun = (prefsData.type == 'APPL');
  144.  
  145.     } else {
  146.  
  147.         /*
  148.          *    Couldn't obtain our prefs.  This is possible if the linker is loaded 
  149.          *    during a project conversion.  Just fill in the TargetInfo struct with 
  150.          *    "innocuous" values.
  151.          */
  152.         
  153.         targetInfo.canRun    = false;
  154.         targetInfo.canDebug    = false;
  155.     }
  156.     
  157.     err = CWSetTargetInfo (inContext, &targetInfo);
  158.     
  159.     return (err);
  160. }
  161.  
  162. CWResult    Link (
  163.     CWPluginContext inContext)
  164. {
  165.     CWTargetInfo    targetInfo;
  166.     SetFilePref        prefsData;
  167.     CWResult        err;
  168.  
  169.     /* load the relevant prefs */
  170.     err = MyGetPreferences (inContext, &prefsData);
  171.     if (err != noErr)
  172.         return (err);
  173.     
  174.     err = CWGetTargetInfo (inContext, &targetInfo);
  175.     if (err != noErr)
  176.         return err;
  177.     
  178.     FInfo                fndrInfo;
  179.     ExtendedFileInfo    fndrXInfo;
  180.         
  181.     err = FSpGetFInfo(&targetInfo.outfile, &fndrInfo);
  182.     if (err == noErr) {
  183.         FSpRstFLock(&targetInfo.outfile);
  184.         if (kNoChange != prefsData.type)
  185.             fndrInfo.fdType = prefsData.type;                    /*the type of the file*/
  186.         if (kNoChange != prefsData.creator)
  187.             fndrInfo.fdCreator = prefsData.creator;                /*file's creator*/
  188.         fndrInfo.fdFlags = prefsData.flags & validAttrBits;        /*flags ex. hasbundle,invisible,locked, etc.*/
  189.     
  190.         err = FSpSetFInfo(&targetInfo.outfile, &fndrInfo);
  191.     }
  192.         
  193.     if (err == noErr) {
  194.         err = FSpGetExtendedFileInfo(&targetInfo.outfile, &fndrXInfo);
  195.     }        
  196.  
  197.     if (err == noErr) {
  198.         fndrXInfo.extendedFinderFlags = prefsData.xflags & validAttrXBits;
  199.         err = FSpSetExtendedFileInfo(&targetInfo.outfile, &fndrXInfo);
  200.     }
  201.     
  202.     if (err == noErr) {        
  203.         if (prefsData.lock) {
  204.             err = FSpSetFLock (&targetInfo.outfile);
  205.         }
  206.     }
  207.  
  208.     err = CWMacOSErrToCWResult (inContext, err); 
  209.     
  210.     return (err);
  211. }
  212.  
  213. CWResult MyGetPreferences (
  214.     CWPluginContext    context,
  215.     SetFilePref*    prefData)
  216. {
  217.     CWMemHandle        prefsHand;
  218.     SetFilePref*    prefsPtr;
  219.     CWResult        err;
  220.  
  221.     /* load the relevant prefs */
  222.     err = CWGetNamedPreferences (context, kSetFilePanelName, &prefsHand);
  223.     if (err != cwNoErr)
  224.         return (err);
  225.  
  226.     err = CWLockMemHandle (context, prefsHand, false, (void**)&prefsPtr);
  227.     if (err != cwNoErr)
  228.         return (err);
  229.  
  230.     *prefData = *prefsPtr;
  231.     err = CWUnlockMemHandle (context, prefsHand);
  232.  
  233.     return err;
  234. }
  235.  
  236. concludeC
  237.  
  238.  
  239.  
  240.